package com.xunfang.portal.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xunfang.portal.model.entity.Book;
import com.xunfang.portal.model.entity.BookCollection;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author scott
* @description 针对表【t_book_collection】的数据库操作Mapper
* @createDate 2025-10-24 09:14:26
* @Entity com.xunfang.portal.model.entity.BookCollection
*/
public interface BookCollectionMapper extends BaseMapper<BookCollection> {

    /**
     * 通过用户ID查询收藏的书籍列表，按收藏的降序排序
     * @param page
     * @param userId
     * @return
     */
    @Select("SELECT b.* FROM `t_book_collection` c INNER JOIN t_book b " +
            "ON c.book_id = b.id " +
            "WHERE user_Id=#{userId} ORDER BY c.id DESC")
    List<Book> findFavoriteBooksByUserId(@Param("userId")Long userId,Page<Book> page);

}




